package wang.aweb.childcar.util;

import org.apache.tomcat.util.codec.binary.Base64;
import wang.aweb.childcar.common.Constant;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密工具
 */
public class Md5Utils {
    public static String getMD5Str(String strvalue) throws NoSuchAlgorithmException {
        MessageDigest md5=MessageDigest.getInstance("MD5");
        byte[] secretBytes=md5.digest(strvalue.getBytes());
        String md5code = new BigInteger(1, secretBytes).toString(16);
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code = "0" + md5code;
        }
        return md5code;

        //return Base64.encodeBase64String(md5.digest((strvalue).getBytes()));
    }
    //用该方法测试生成的MD5的值
    public static void main(String[] args) throws NoSuchAlgorithmException {
        String md5=getMD5Str("1234");
        System.out.println(md5);
    }
}
